const express = require('express')
const swaggerUI = require('swagger-ui-express')
//设置跨域
const cors = require('cors');
//使用全局错误捕获
const globalErrorCapture = require('./middleware/globalErrorCapture')
// 加一个注释，用以说明，本项目代码可以任意定制更改
const app = express()
// 使用cors中间件
app.use(cors());
//引入swagger
const swaggerspc = require('./config/swagger')
//开启静态资源
app.use(express.static('public'));
const PORT = process.env.PORT || 3000
//内置中间件
app.use(express.json())
app.use(express.urlencoded())
// 挂载路由
const router = require('./router')
app.use('/api', router)
app.use('/docs',swaggerUI.serve,swaggerUI.setup(swaggerspc))

// 挂载统一处理服务端错误中间件
app.use(globalErrorCapture)

app.listen(PORT, () => {
  console.log(`Server is running at http://192.168.18.57:${PORT}`)
})
